//
//  ViewController.m
//  JKXib
//
//  Created by 王冲 on 2019/7/5.
//  Copyright © 2019 王冲. All rights reserved.
//

#import "ViewController.h"
#import "JKUIView.h"
#import "TestViewController1.h"
#import "Person.h"
#import "JKCollectionViewCarousel.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) UITableView *tableview;

@property(nonatomic,strong) NSMutableArray *dataArray;


@property(nonatomic,strong) NSString *name;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    JKCollectionViewCarousel *collectionViewCarousel = [[JKCollectionViewCarousel alloc]initWithFrame:CGRectMake(20, 100, JK_SCREEN_WIDTH-40, 150)];
    [self.view addSubview:collectionViewCarousel];
    
    Person *person = [Person new];

    // [self.dataArray addObjectsFromArray:@[@"Xib测试"]];
    
    // [self.view addSubview:self.tableview];
    
//
//    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    headView.backgroundColor = [UIColor redColor];
//    self.tableview.tableHeaderView = headView;
    
    
//    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    headView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:headView];
//
//    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 60, 60)];
//    label.backgroundColor = [UIColor yellowColor];
//    [headView addSubview:label];
//
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)];
//    [headView addGestureRecognizer:tap];
    
    
}

-(void)click{
    
    NSLog(@"手势x打印");
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSString *cell_name = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row]];
    
    if ([cell_name isEqualToString:@"Xib测试"]) {
        
        TestViewController1 *test1Vc = [TestViewController1 new];
        [self.navigationController pushViewController:test1Vc animated:YES];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.backgroundColor = JKRandomColor;
    cell.textLabel.text = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row]];
    
    return cell;
}


-(UITableView *)tableview{
    
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, JKNaviHeight, JK_SCREEN_WIDTH, JK_SCREEN_HEIGHT-JKNaviHeight) style:UITableViewStylePlain];
        _tableview.dataSource = self;
        _tableview.delegate = self;
        
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        if (@available(iOS 11.0, *)) {
            
            _tableview.estimatedRowHeight = 0;
            _tableview.estimatedSectionFooterHeight = 0;
            _tableview.estimatedSectionHeaderHeight = 0;
            _tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            // 小于11.0的不做操作
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
    }
    
    return _tableview;
}


-(void)test{
    
    // .c 文件编译后变成 .o 文件
    // xib 文件打包后c变成 nib 文件，打包后是不存在xib文件的
    // 注意点：如果一个控件是从xib加载出来的，不设置尺寸会有默认的尺寸（在xib中设置的尺寸）
    
    
    // 加载xib的第一种方式
    // UIView *view = [[NSBundle mainBundle]loadNibNamed:@"test" owner:nil options:nil].firstObject;
    // 加载xib的第二种方式
    UIView *view1 = [[UINib nibWithNibName:@"test" bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil].firstObject;
    view1.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:view1];
    
    // 本质也是在遍历
    // [view1 viewWithTag:<#(NSInteger)#>]
    
    JKUIView *jkUIView = [JKUIView setJKUIView];
    jkUIView.frame = CGRectMake(40, 300, 300, 100);
    [self.view addSubview:jkUIView];
}

@end
